//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: '欢迎使用小智',
    userInfo: {},
    otherDataList:[],
    actionSheetList:['车辆管理','管理员登陆']
  },
  onLoad: function () {
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
    try {
      var res = wx.getStorageInfoSync()
      that.setData({
        otherDataList:[{"name":"如何使用小程序","describe":"小程序大未来","submenu":true},{"name":"清除缓存数据","describe":res.currentSize<2?"0kb":res.currentSize+"kb","submenu":false},{"name":"联系客服","describe":"","submenu":true},{"name":"关于","describe":"","submenu":true}]
      })
    } catch (e) {
      // Do something when catch error
    }
  },
  otherItem: function (e) {
    var that = this
    switch(e.currentTarget.dataset.index){
      case 0:
        wx.navigateTo({
          url: '/pages/smartlife/guide/guide'
        })
      break;
      case 1:
        wx.showModal({
          title: '警告',
          content: '清除数据后，您的违章车辆信息、公交线路信息等将不再存在，确定要清除所有数据吗？',
          success: function(res) {
            if (res.confirm) {
              try {
                wx.clearStorageSync()
                wx.showToast({
                  title: '清除成功',
                  icon: 'success'
                })
                that.setData({
                  otherDataList:[{"name":"如何使用小程序","describe":"小程序大未来","submenu":true},{"name":"清除缓存数据","describe":"0kb","submenu":false},{"name":"联系客服","describe":"","submenu":true},{"name":"关于","describe":"","submenu":true}]
                })
              } catch(e) {
                wx.showToast({
                  title: '清除失败',
                  image: '/image/error.png'
                })
              }
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      break;
      case 2:
        wx.navigateTo({
              url: '/pages/mine/customservice/customservice'
            })
      break;
      case 3:
        wx.navigateTo({
          url: '/pages/mine/about/about'
        })
      break;
      default:

      break
    }
  },
  headLongClick:function(e){
    var that = this
    wx.showActionSheet({
      itemList: that.data.actionSheetList,
      success: function(res) {
        // console.log(res.tapIndex)
        switch(res.tapIndex){
          case 0:
            wx.navigateTo({
              url: '/pages/smartlife/violate/violate'
            })
          break;
          case 1:
            wx.navigateTo({
              url: '/pages/mine/manager_list/manager_list'
            })
          break;
          default:

          break;
        }
      },
      fail: function(res) {
        // console.log(res.errMsg)
      }
    })
  }
})
